<?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=Sabdul</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=Sabdul"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Sabdul"/>
	<updated>2026-05-08T15:59:19Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=92368</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=92368"/>
		<updated>2014-12-03T06:03:20Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Reduce Instance Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. Here persist_survey method has been created in the SurveyResponseHelper to minimize instance variables.&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    for question in @questions&lt;br /&gt;
    @new = SurveyResponse.new&lt;br /&gt;
    @new.survey_id = @survey_id&lt;br /&gt;
    @new.question_id = question.id&lt;br /&gt;
    @new.assignment_id = @assignment_id&lt;br /&gt;
    @new.survey_deployment_id=params[:survey_deployment_id]&lt;br /&gt;
    @new.email = params[:email]&lt;br /&gt;
    @new.score = @scores[question.id.to_s]&lt;br /&gt;
    @new.comments = @comments[question.id.to_s]&lt;br /&gt;
    @new.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for question in @questions&lt;br /&gt;
    SurveyResponseHelper::persist_survey(@survey_id, question.id, @assignment_id, params[:survey_deployment_id], params[:email])&lt;br /&gt;
  end&lt;br /&gt;
  if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Using Routing Helpers===&lt;br /&gt;
Creation of a resourceful route will also expose a number of helpers to the controllers in the application. We modified the routes.rb file to include all the actions in the controller.&lt;br /&gt;
&lt;br /&gt;
resources :survey_response do&lt;br /&gt;
    collection do&lt;br /&gt;
        get :view_responses&lt;br /&gt;
        get :begin_survey&lt;br /&gt;
        get :comments&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
The resourceful routes generated the helpers given below:&lt;br /&gt;
&lt;br /&gt;
    view_responses_survey_response_index_path  returns /survey_response/view_responses&lt;br /&gt;
&lt;br /&gt;
    begin_survey_survey_response_index_path  returns /survey_response/begin_survey&lt;br /&gt;
&lt;br /&gt;
    comments_survey_response_index_path  returns /survey_response/comments&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Testing was performed by running 2 different VCL instances one with the original code and the other with the re-factored code. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey_original.png|500px|frame|left| ]]&lt;br /&gt;
Begin Survey action was broken in the original source code, we made fixes to make the functionality work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
The Course Evaluation action works as expected after refactoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|500px|frame|left| ]]&lt;br /&gt;
The View Response action was broken and fix is made to display the functionality properly.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
Pending course evaluation works as expected after code re-factoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|500px|frame|left| ]]&lt;br /&gt;
The action for View Response comments was not routed properly, necessary changes have been made to call the appropriate action&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=92367</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=92367"/>
		<updated>2014-12-03T06:02:44Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Reduce Instance Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    for question in @questions&lt;br /&gt;
    @new = SurveyResponse.new&lt;br /&gt;
    @new.survey_id = @survey_id&lt;br /&gt;
    @new.question_id = question.id&lt;br /&gt;
    @new.assignment_id = @assignment_id&lt;br /&gt;
    @new.survey_deployment_id=params[:survey_deployment_id]&lt;br /&gt;
    @new.email = params[:email]&lt;br /&gt;
    @new.score = @scores[question.id.to_s]&lt;br /&gt;
    @new.comments = @comments[question.id.to_s]&lt;br /&gt;
    @new.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for question in @questions&lt;br /&gt;
    SurveyResponseHelper::persist_survey(@survey_id, question.id, @assignment_id, params[:survey_deployment_id], params[:email])&lt;br /&gt;
  end&lt;br /&gt;
  if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 Here persist_survey method has been created in the SurveyResponseHelper to minimize instance variables.&lt;br /&gt;
&lt;br /&gt;
===Using Routing Helpers===&lt;br /&gt;
Creation of a resourceful route will also expose a number of helpers to the controllers in the application. We modified the routes.rb file to include all the actions in the controller.&lt;br /&gt;
&lt;br /&gt;
resources :survey_response do&lt;br /&gt;
    collection do&lt;br /&gt;
        get :view_responses&lt;br /&gt;
        get :begin_survey&lt;br /&gt;
        get :comments&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
The resourceful routes generated the helpers given below:&lt;br /&gt;
&lt;br /&gt;
    view_responses_survey_response_index_path  returns /survey_response/view_responses&lt;br /&gt;
&lt;br /&gt;
    begin_survey_survey_response_index_path  returns /survey_response/begin_survey&lt;br /&gt;
&lt;br /&gt;
    comments_survey_response_index_path  returns /survey_response/comments&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Testing was performed by running 2 different VCL instances one with the original code and the other with the re-factored code. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey_original.png|500px|frame|left| ]]&lt;br /&gt;
Begin Survey action was broken in the original source code, we made fixes to make the functionality work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
The Course Evaluation action works as expected after refactoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|500px|frame|left| ]]&lt;br /&gt;
The View Response action was broken and fix is made to display the functionality properly.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
Pending course evaluation works as expected after code re-factoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|500px|frame|left| ]]&lt;br /&gt;
The action for View Response comments was not routed properly, necessary changes have been made to call the appropriate action&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91547</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91547"/>
		<updated>2014-11-06T06:39:47Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Reduce Instance Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    for question in @questions&lt;br /&gt;
    @new = SurveyResponse.new&lt;br /&gt;
    @new.survey_id = @survey_id&lt;br /&gt;
    @new.question_id = question.id&lt;br /&gt;
    @new.assignment_id = @assignment_id&lt;br /&gt;
    @new.survey_deployment_id=params[:survey_deployment_id]&lt;br /&gt;
    @new.email = params[:email]&lt;br /&gt;
    @new.score = @scores[question.id.to_s]&lt;br /&gt;
    @new.comments = @comments[question.id.to_s]&lt;br /&gt;
    @new.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for question in @questions&lt;br /&gt;
    SurveyResponseHelper::persist_survey(@survey_id, question.id, @assignment_id, params[:survey_deployment_id], params[:email])&lt;br /&gt;
  end&lt;br /&gt;
  if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Using Routing Helpers===&lt;br /&gt;
Creation of a resourceful route will also expose a number of helpers to the controllers in the application. We modified the routes.rb file to include all the actions in the controller.&lt;br /&gt;
&lt;br /&gt;
resources :survey_response do&lt;br /&gt;
    collection do&lt;br /&gt;
        get :view_responses&lt;br /&gt;
        get :begin_survey&lt;br /&gt;
        get :comments&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
The resourceful routes generated the helpers given below:&lt;br /&gt;
&lt;br /&gt;
view_responses_survey_response_index_path  returns /survey_response/view_responses&lt;br /&gt;
begin_survey_survey_response_index_path  returns /survey_response/begin_survey&lt;br /&gt;
comments_survey_response_index_path  returns /survey_response/comments&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host http://152.46.19.10:3000/&amp;lt;/code&amp;gt; the refactored instance is setup. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey_original.png|500px|frame|left| ]]&lt;br /&gt;
Begin Survey action was broken in the original source code, we made fixes to make the functionality work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
The Course Evaluation action works as expected after refactoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|500px|frame|left| ]]&lt;br /&gt;
The View Response action was broken and fix is made to display the functionality properly.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
Pending course evaluation works as expected after code re-factoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|500px|frame|left| ]]&lt;br /&gt;
The action for View Response comments was not routed properly, necessary changes have been made to call the appropriate action&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91546</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91546"/>
		<updated>2014-11-06T06:30:46Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Modification to Existing Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Using Routing Helpers===&lt;br /&gt;
Creation of a resourceful route will also expose a number of helpers to the controllers in the application. We modified the routes.rb file to include all the actions in the controller.&lt;br /&gt;
&lt;br /&gt;
resources :survey_response do&lt;br /&gt;
    collection do&lt;br /&gt;
        get :view_responses&lt;br /&gt;
        get :begin_survey&lt;br /&gt;
        get :comments&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
The resourceful routes generated the helpers given below:&lt;br /&gt;
&lt;br /&gt;
view_responses_survey_response_index_path  returns /survey_response/view_responses&lt;br /&gt;
begin_survey_survey_response_index_path  returns /survey_response/begin_survey&lt;br /&gt;
comments_survey_response_index_path  returns /survey_response/comments&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host http://152.46.19.10:3000/&amp;lt;/code&amp;gt; the refactored instance is setup. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey_original.png|500px|frame|left| ]]&lt;br /&gt;
Begin Survey action was broken in the original source code, we made fixes to make the functionality work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
The Course Evaluation action works as expected after refactoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|500px|frame|left| ]]&lt;br /&gt;
The View Response action was broken and fix is made to display the functionality properly.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
Pending course evaluation works as expected after code re-factoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|500px|frame|left| ]]&lt;br /&gt;
The action for View Response comments was not routed properly, necessary changes have been made to call the appropriate action&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91545</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91545"/>
		<updated>2014-11-06T06:28:11Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Modification to Existing Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
===Using Routing Helpers===&lt;br /&gt;
Creation of a resourceful route will also expose a number of helpers to the controllers in the application. We modified the routes.rb file to include all the actions in the controller.&lt;br /&gt;
&lt;br /&gt;
resources :survey_response do&lt;br /&gt;
    collection do&lt;br /&gt;
        get :view_responses&lt;br /&gt;
        get :begin_survey&lt;br /&gt;
        get :comments&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
The resourceful routes generated the helpers given below:&lt;br /&gt;
&lt;br /&gt;
view_responses_survey_response_index_path  returns /survey_response/view_responses&lt;br /&gt;
begin_survey_survey_response_index_path  returns /survey_response/begin_survey&lt;br /&gt;
comments_survey_response_index_path  returns /survey_response/comments&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host http://152.46.19.10:3000/&amp;lt;/code&amp;gt; the refactored instance is setup. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey_original.png|500px|frame|left| ]]&lt;br /&gt;
Begin Survey action was broken in the original source code, we made fixes to make the functionality work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
The Course Evaluation action works as expected after refactoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|500px|frame|left| ]]&lt;br /&gt;
The View Response action was broken and fix is made to display the functionality properly.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
Pending course evaluation works as expected after code re-factoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|500px|frame|left| ]]&lt;br /&gt;
The action for View Response comments was not routed properly, necessary changes have been made to call the appropriate action&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91543</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91543"/>
		<updated>2014-11-06T06:05:01Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host http://152.46.19.10:3000/&amp;lt;/code&amp;gt; the refactored instance is setup. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey_original.png|500px|frame|left| ]]&lt;br /&gt;
Begin Survey action was broken in the original source code, we made fixes to make the functionality work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
The Course Evaluation action works as expected after refactoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|500px|frame|left| ]]&lt;br /&gt;
The View Response action was broken and fix is made to display the functionality properly.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
Pending course evaluation works as expected after code re-factoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|500px|frame|left| ]]&lt;br /&gt;
The action for View Response comments was not routed properly, necessary changes have been made to call the appropriate action&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91542</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91542"/>
		<updated>2014-11-06T05:55:41Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host http://152.46.19.10:3000/&amp;lt;/code&amp;gt; the refactored instance is setup. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey_original.png|500px|frame|left| ]]&lt;br /&gt;
Begin Survey action was broken in the original source code, we made fixes to make the functionality work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
The Course Evaluation action works as expected after refactoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|500px|frame|left| ]]&lt;br /&gt;
The View Response action was broken and fix is made to display the functionality properly.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
Pending course evaluation works as expected after code re-factoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|500px|frame|left| ]]&lt;br /&gt;
The action for View Response comments was not routed properly, necessary changes have been made to call the appropriate action&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91541</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91541"/>
		<updated>2014-11-06T05:51:53Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host http://152.46.19.10:3000/&amp;lt;/code&amp;gt; the refactored instance is setup. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey_original.png|500px|frame|left| ]]&lt;br /&gt;
Begin Survey action was broken in the original source code, we made fixes to make the functionality work.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
The Course Evaluation action works as expected after refactoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|500px|frame|left| ]]&lt;br /&gt;
The View Response action was broken and fix is made to display the functionality properly.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
Pending course evaluation works as expected after code re-factoring&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|500px|frame|left| ]]&lt;br /&gt;
The action for View Response comments was not routed properly, necessary changes have been made to call the appropriate action&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:View_responses_refactored.png&amp;diff=91536</id>
		<title>File:View responses refactored.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:View_responses_refactored.png&amp;diff=91536"/>
		<updated>2014-11-06T05:44:40Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:View responses refactored.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:View_responses.png&amp;diff=91534</id>
		<title>File:View responses.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:View_responses.png&amp;diff=91534"/>
		<updated>2014-11-06T05:44:26Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:View responses.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_refactored.png&amp;diff=91533</id>
		<title>File:Response comments refactored.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_refactored.png&amp;diff=91533"/>
		<updated>2014-11-06T05:44:12Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:Response comments refactored.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_original.png&amp;diff=91532</id>
		<title>File:Response comments original.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_original.png&amp;diff=91532"/>
		<updated>2014-11-06T05:43:51Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:Response comments original.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Pending_course_evaluation_refactored.png&amp;diff=91531</id>
		<title>File:Pending course evaluation refactored.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Pending_course_evaluation_refactored.png&amp;diff=91531"/>
		<updated>2014-11-06T05:43:31Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:Pending course evaluation refactored.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Course_evaluation.png&amp;diff=91530</id>
		<title>File:Course evaluation.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Course_evaluation.png&amp;diff=91530"/>
		<updated>2014-11-06T05:43:10Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:Course evaluation.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey_refactored.png&amp;diff=91529</id>
		<title>File:Begin survey refactored.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey_refactored.png&amp;diff=91529"/>
		<updated>2014-11-06T05:42:50Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:Begin survey refactored.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey_original.png&amp;diff=91527</id>
		<title>File:Begin survey original.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey_original.png&amp;diff=91527"/>
		<updated>2014-11-06T05:42:20Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:Begin survey original.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91526</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91526"/>
		<updated>2014-11-06T05:36:20Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host http://152.46.19.10:3000/&amp;lt;/code&amp;gt; the refactored instance is setup. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey_original.png|500px|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|500px|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|500px|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|500px|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|500px|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|500px|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91520</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91520"/>
		<updated>2014-11-06T04:53:53Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host http://152.46.19.10:3000/&amp;lt;/code&amp;gt; the refactored instance is setup. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey_original.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey_refactored.png&amp;diff=91519</id>
		<title>File:Begin survey refactored.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey_refactored.png&amp;diff=91519"/>
		<updated>2014-11-06T04:52:47Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91518</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91518"/>
		<updated>2014-11-06T04:51:21Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host http://152.46.19.10:3000/&amp;lt;/code&amp;gt; the refactored instance is setup. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey_original.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey_original.png&amp;diff=91517</id>
		<title>File:Begin survey original.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey_original.png&amp;diff=91517"/>
		<updated>2014-11-06T04:50:40Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey.png&amp;diff=91516</id>
		<title>File:Begin survey.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey.png&amp;diff=91516"/>
		<updated>2014-11-06T04:49:52Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:Begin survey.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey.png&amp;diff=91515</id>
		<title>File:Begin survey.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey.png&amp;diff=91515"/>
		<updated>2014-11-06T04:49:05Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:Begin survey.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey.png&amp;diff=91511</id>
		<title>File:Begin survey.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Begin_survey.png&amp;diff=91511"/>
		<updated>2014-11-06T04:44:05Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:Begin survey.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91506</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91506"/>
		<updated>2014-11-06T04:37:13Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host http://152.46.19.10:3000/&amp;lt;/code&amp;gt; the refactored instance is setup. While performing the manual testing we noticed that when new course evaluations are created, the survey participants are random users and participants selection is not based on the courses. However, while displaying the pending course evaluations in the course evaluation list view, the courses are taken into consideration. Because of this difference we were not able to submit survey responses and view them.&lt;br /&gt;
In below images we have shown that the output after refactoring and output without re-factoring for all actions in the SurveyResponsesController.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|frame|left| ]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91505</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91505"/>
		<updated>2014-11-06T04:30:35Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Response Comments Re-factored&lt;br /&gt;
! View of Original Response Comments Re-factored&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Response_comments_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:Response_comments_original.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_refactored.png&amp;diff=91504</id>
		<title>File:Response comments refactored.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_refactored.png&amp;diff=91504"/>
		<updated>2014-11-06T04:29:37Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:Response comments refactored.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_refactored.png&amp;diff=91503</id>
		<title>File:Response comments refactored.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_refactored.png&amp;diff=91503"/>
		<updated>2014-11-06T04:28:15Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_original.png&amp;diff=91502</id>
		<title>File:Response comments original.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_original.png&amp;diff=91502"/>
		<updated>2014-11-06T04:27:33Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:Response comments original.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_original.png&amp;diff=91500</id>
		<title>File:Response comments original.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Response_comments_original.png&amp;diff=91500"/>
		<updated>2014-11-06T04:26:02Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91499</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91499"/>
		<updated>2014-11-06T04:19:33Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Removing comments and cleaning up code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Clean up===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91498</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91498"/>
		<updated>2014-11-06T04:19:09Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Reducing the number of instance variables per action to one */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reduce Instance Variables===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91497</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91497"/>
		<updated>2014-11-06T04:18:33Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Changing declarations of Arrays and Hashes as per Ruby 1.9 standards */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Ruby 1.9 standards for Array and Hashes===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91496</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91496"/>
		<updated>2014-11-06T04:17:44Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Move active record queries to the model or another class */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active Record Queries in Model Class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91495</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91495"/>
		<updated>2014-11-06T04:16:35Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Pluralize the SurveyResponseController class to SurveyResponsesController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize Controller Class===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91494</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91494"/>
		<updated>2014-11-06T04:15:33Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Class''': Controllers as per Ruby conventions should be plural.&lt;br /&gt;
*'''Using Helper classes''': No class should be containing lot of code, a better practice is to have all active record queries with in the model and in order to keep as much as Ruby code out of the views, helpers are used. Helpers are the only methods you can access, other than instance methods for an instance you have access to.&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize the SurveyResponseController class to SurveyResponsesController===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91492</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91492"/>
		<updated>2014-11-06T04:00:24Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.19.10:3000/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Fat Classes&amp;lt;/b&amp;gt;: No class should be fat. Ever. There is no need for your controllers, models or views to be fat; this shows laziness, as there's been no thought given to the application's design outside of deciding to use a particular framework.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad Class names&amp;lt;/b&amp;gt;: A good class name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of functionality handled. &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Method''': Renaming identifiers can reduce the need for code comments and nearly always helps to promote greater clarity.&lt;br /&gt;
*'''Introduce Explaining Variable''': So here is a technique specifically based around the premise of renaming.&lt;br /&gt;
&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Inline Method''': Sometimes you want the opposite of the Extract Method technique. Imagine a method exists whose content is already simple and clear, and whose identifier adds no extra benefit. So to fix this problem we'll convert the method invocation into an inlined piece of code.&lt;br /&gt;
&lt;br /&gt;
*'''Pull Up Method''': When you have duplicated code across two separate classes then the best refactoring technique to implement is to pull that duplicate code up into a super class so we DRY (Don't Repeat Yourself) out the code and allow it to be used in multiple places without duplication (meaning changes in future only have to happen in one place).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Introduce Named Parameter''':When method arguments are unclear then convert them into named parameters so they become clearer (and easier to remember).&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize the SurveyResponseController class to SurveyResponsesController===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91489</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91489"/>
		<updated>2014-11-06T03:32:57Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.18.142:3000&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/nmpedema/expertiza &amp;lt;ref&amp;gt;[https://github.com/nmpedema/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/448 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/448 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize the SurveyResponseController class to SurveyResponsesController===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91487</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91487"/>
		<updated>2014-11-06T03:27:14Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.142/:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user2&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/sanjeevs/expertiza &amp;lt;ref&amp;gt;[https://github.com/sanjeevs/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/444 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/444 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize the SurveyResponseController class to SurveyResponsesController===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91486</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91486"/>
		<updated>2014-11-06T03:25:47Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/sanjeevs/expertiza &amp;lt;ref&amp;gt;[https://github.com/sanjeevs/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/444 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/444 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize the SurveyResponseController class to SurveyResponsesController===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91485</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91485"/>
		<updated>2014-11-06T03:20:45Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize the SurveyResponseController class to SurveyResponsesController===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91484</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91484"/>
		<updated>2014-11-06T03:20:29Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize the SurveyResponseController class to SurveyResponsesController===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91483</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91483"/>
		<updated>2014-11-06T03:20:04Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize the SurveyResponseController class to SurveyResponsesController===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#projectLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91482</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91482"/>
		<updated>2014-11-06T03:19:36Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize the SurveyResponseController class to SurveyResponsesController===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  http://152.46.18.142/&amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#projectLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91481</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91481"/>
		<updated>2014-11-06T03:18:24Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize the SurveyResponseController class to SurveyResponsesController===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#projectLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Pending Course Evaluations&lt;br /&gt;
! View of Original Pending Course Evaluations&lt;br /&gt;
|-&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:pending_course_evaluation_refactored.png|frame|left| ]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Pending_course_evaluation_refactored.png&amp;diff=91480</id>
		<title>File:Pending course evaluation refactored.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Pending_course_evaluation_refactored.png&amp;diff=91480"/>
		<updated>2014-11-06T03:14:43Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:View_responses_refactored.png&amp;diff=91472</id>
		<title>File:View responses refactored.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:View_responses_refactored.png&amp;diff=91472"/>
		<updated>2014-11-06T03:06:21Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:View responses refactored.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:View_responses.png&amp;diff=91470</id>
		<title>File:View responses.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:View_responses.png&amp;diff=91470"/>
		<updated>2014-11-06T03:06:03Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: uploaded a new version of &amp;amp;quot;File:View responses.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91469</id>
		<title>CSC/ECE 517 Fall 2014/oss E1462 nms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1462_nms&amp;diff=91469"/>
		<updated>2014-11-06T03:02:20Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring SurveyResponsesController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is an open source web portal for the use of both students and professors. Expertiza allows us to create reusable learning objects through peer review. It allows project submission, team creation and the submission of almost any document type, including URLs and wiki pages. Students can access their pending and finished assignments, they can do peer reviews on several topics and projects. It is developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code has been forked and cloned for making modifications to the to survey responses controller. &lt;br /&gt;
&lt;br /&gt;
This wiki provides an insight into our contributions to the OSS Expertiza application, focusing on Refactoring the SurveyResponses Controller.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
This class creates surveys and records the responses which can be viewed. On submitting the responses, the scores and comments are posted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; SurveyResponsesController.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;Creates surveys, submitting surveys, views responses, posts scores and comments.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
* Pluralize the class SurveyResponseController to SurveyResponsesController&lt;br /&gt;
* Changing declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Use of routing helpers instead of hardcoded URLs&lt;br /&gt;
* Move active record queries to the model or another class&lt;br /&gt;
* Reducing the number of instance variables per action to one&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralize the SurveyResponseController class to SurveyResponsesController===&lt;br /&gt;
* A new survey_responses_controller.rb file is added : As per Ruby on Rails convention, controller names get pluralized while model names are singular. So, the controller name becomes survey_responses_controller instead of survey_response_controller for SurveyResponse modelclass.&lt;br /&gt;
&lt;br /&gt;
===Changing declarations of Arrays and Hashes as per Ruby 1.9 standards===&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = Array.new&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = Hash.new  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
  @responses = []&lt;br /&gt;
    &lt;br /&gt;
#view_responses&lt;br /&gt;
  this_response_survey = {}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Move active record queries to the model or another class===&lt;br /&gt;
&lt;br /&gt;
Controllers are best at parsing the inputs, they call the appropriate models, and then format the outputs. It is desirable to have a skinny controller responsible for parsing inputs and models doing actual validation. A bunch of Active Record queries that existed in survey_responses_controller have been moved to SurveyResponse model. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;assignment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
    else&lt;br /&gt;
      surveylist = SurveyResponse.where( [&amp;quot;survey_deployment_id = ? and survey_id = ?&amp;quot;, params[:id], survey.id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
SurveyResponse.get_survey_list and SurveyResponse.get_survey_list_with_deploy_id methods have been created in SurveyResponse model for active record operations.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     #view_responses&lt;br /&gt;
     if !params[:course_eval]&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list(params[:id], survey.id)&lt;br /&gt;
     else&lt;br /&gt;
      survey_list = SurveyResponse.get_survey_list_with_deploy_id( params[:id], survey.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Reducing the number of instance variables per action to one===&lt;br /&gt;
It desirable not to have more than one instance variables in a controller action as it indicates increased coupling. Our goal should be reducing coupling as much as possible and view should have direct access to as few instance variables as possible. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    @surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
survey_responses_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#submit&lt;br /&gt;
     if !params[:survey_deployment_id]&lt;br /&gt;
    surveys = SurveyHelper::get_assigned_surveys(@assignment_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Removing comments and cleaning up code===&lt;br /&gt;
Comments and extra spaces have been removed and conventions have been followed to enhance readability of the code.&lt;br /&gt;
==Testing==&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3000 of host  &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 of host &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the survey response controller functionality a user should have courses evaluation surveys pending.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#projectLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Begin Survey&lt;br /&gt;
! View of Original Begin Survey&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
| [[File:Begin_survey.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored Course Evaluation Survey&lt;br /&gt;
! View of Original Course Evaluation Survey&lt;br /&gt;
|-&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
| [[File:course_evaluation.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
! View of Re-factored View Responses&lt;br /&gt;
! View of Original View Responses&lt;br /&gt;
|-&lt;br /&gt;
| [[File:view_responses_refactored.png|frame|left| ]]&lt;br /&gt;
| [[File:view_responses.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[https://github.com/nmpedema/expertiza.git Git Repository]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:View_responses.png&amp;diff=91467</id>
		<title>File:View responses.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:View_responses.png&amp;diff=91467"/>
		<updated>2014-11-06T02:54:33Z</updated>

		<summary type="html">&lt;p&gt;Sabdul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sabdul</name></author>
	</entry>
</feed>